package com.tjsinfo.tjsoa.system.bo;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.tjsinfo.tjsoa.Dao.IHibernateDao;
import com.tjsinfo.tjsoa.Dao.IQbcDao;
import com.tjsinfo.tjsoa.system.vo.TSystemUserRole;

public class SystemUserRoleBO implements ISystemUserRoleBO {
	private IHibernateDao hibernateDao;
	private IQbcDao qbcDao;
	
	public IQbcDao getQbcDao() {
		return qbcDao;
	}

	public void setQbcDao(IQbcDao qbcDao) {
		this.qbcDao = qbcDao;
	}

	public IHibernateDao getHibernateDao() {
		return hibernateDao;
	}

	public void setHibernateDao(IHibernateDao hibernateDao) {
		this.hibernateDao = hibernateDao;
	}

	public Integer addSystemUserRole(TSystemUserRole systemUserRole) {
		// TODO Auto-generated method stub
		return hibernateDao.save(systemUserRole);
	}

	public Boolean selectUserRoleByUserId(Integer roleid, Integer userid) {
		// TODO Auto-generated method stub
		DetachedCriteria criteria = DetachedCriteria.forClass(TSystemUserRole.class);
		criteria.add(Restrictions.eq("roleId", roleid));
		criteria.add(Restrictions.eq("userId", userid));
		if (qbcDao.getCriteria(criteria).size() > 0) {
			return true;
		} else {
			return false;
		}
		
	}

	public Boolean deleteUserRole(TSystemUserRole systemUserRole) {
		// TODO Auto-generated method stub
		try {
			hibernateDao.delete(systemUserRole);
			return true;
		} catch (RuntimeException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}
		
	}

	public List<TSystemUserRole> seleteSystemUserRoleByUserId(Integer userid) {
		// TODO Auto-generated method stub
		DetachedCriteria criteria = DetachedCriteria.forClass(TSystemUserRole.class);
		criteria.add(Restrictions.eq("userId", userid));
		return qbcDao.getCriteria(criteria);
	}

	public Boolean deleteSystemUserRoleByUserid(Integer userid) {
		// TODO Auto-generated method stub
		try {
			List<TSystemUserRole> list = seleteSystemUserRoleByUserId(userid);
			for (TSystemUserRole systemUserRole : list) {
				deleteUserRole(systemUserRole);
			}
			return true;
		} catch (RuntimeException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}
		
	}

}
